import type { Request } from 'express'
import { tagService } from '@server/services/tag-service'
import { ApiResponse } from '@data/api'
import { NotFoundError } from '@server/error/errors'

export default async function getTagById(request: Request) {
  const id = request.params.id
  const tag = await tagService.getTagById(id)

  if (!tag) {
    throw new NotFoundError('Tag not found')
  }

  const response: ApiResponse = {
    success: true,
    data: tag,
  }

  return response
}
